package com.ipt.frm.pw;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ipartek.formacion.dado.beans.Alumno;
import com.ipartek.formacion.dado.ddbb.DAOFactory;
import com.ipartek.formacion.dado.excepciones.AlumnoException;
import com.ipartek.formacion.dado.interfaces.InterfaceAlumnoDAO;

/**
 * Servlet implementation class servletRanking
 */
public class ServletRanking extends ServletMaestro {
	private static final long serialVersionUID = 1L;

	private static DAOFactory myDao = DAOFactory
			.getDAOFactory(DAOFactory.MYSQL);

	// DAO ALUMNOS
	public static InterfaceAlumnoDAO alumnoDAO = myDao.getInterfaceAlumnoDAO();

	public ArrayList<Alumno> listaAlumnos = new ArrayList<>();
	public Alumno al;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ServletRanking() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// ArrayList<Alumno> listaAlumnos = alumnoDAO.getAlumnos();

		try {
			al = new Alumno("Iker", "Fernandez", "Martin", "72398609Z",
					"rekifm@gmail.com");
		} catch (AlumnoException e) {
			e.printStackTrace();
		}
		listaAlumnos.add(al);

		request.setAttribute("alumnos", listaAlumnos);
		request.setAttribute("titulo", "Ranking");
		RequestDispatcher dispacher = this.getServletContext()
				.getRequestDispatcher("/ranking.jsp");
		dispacher.forward(request, response);
		listaAlumnos.remove(0);
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

}
